package com.hot12345.server.DBConnection;

 
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

 
public class TianyaDBConnectionProvider {

	private static Logger logger = Logger.getLogger(TianyaDBConnectionProvider.class);

 

	private static boolean shutDown = false;

	private static Object initLock = new Object();
 


	/**
 
	 * 
	 * @param poolName
	 *            String
	 * @return Connection
	 * @throws SQLException 
	 */
	public static Connection getConnection(String poolName)
			throws Exception {
	
//		DataSourceFactory dsf = new ProxoolDataSourceFactory();
		/*String poolValue = ReadProperties.readValue(poolName);*/
		if(poolName==null || "".equals(poolName)){
//			poolName = "defaultDs";
			logger.error("poolName is null");
			throw new Exception("poolName is null");
		}
		
		/*String webInfclasses = TianyaDBConnectionProvider.class.getResource("/").getPath();
		//webInfclasses = webInfclasses.replaceAll("/webapps", "");//开发的时候是web目录，不是webapps目录
		String filePath = webInfclasses + poolValue;
		logger.info("dataSource file path:" + filePath);
		Map map = null;
		try {
			map = new ReadXmlFile().getXMLPropertyToMap(filePath);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		dsf.initialize(map);
		logger.debug("dsf=========================" + dsf);
		logger.debug("dsf.getDataSource()=========================" + dsf.getDataSource());
		logger.debug("dsf.getDataSource().getConnection()=========================" + dsf.getDataSource().getConnection());
		return dsf.getDataSource().getConnection(); //获取获取连接池
		*/
		return IbatisConnectCommImpl.getSqlMapClient(poolName).getDataSource().getConnection();
//	   return   DriverManager.getConnection(poolName); //获取连接池
	 
       // return TianyaDBConnectionProvider.getConnectionNotFromPool(poolName);
	}  
 
   
	/**
	 * test
	 * 
	 * @param arg
	 * @throws Exception
	 */
	public static void main(String arg[]) throws Exception {

		System.out.println("CCC"
				+ TianyaDBConnectionProvider
						.getConnection("travel"));
                      
	}

}
